<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="110px"
    >
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
        <el-button
          :icon="!isOpen ? 'el-icon-arrow-down' : 'el-icon-arrow-up'"
          size="mini"
          @click="shouqi"
          >展开/收起</el-button
        >
      </el-form-item>
      <div v-if="isOpen">
        <el-form-item label="日期" prop="dataDate">
          <el-date-picker
            clearable
            v-model="queryParams.dataDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="品牌" prop="brand">
          <el-input
            v-model="queryParams.brand"
            placeholder="请输入品牌"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="渠道" prop="shopId">
          <el-input
            v-model="queryParams.shopId"
            placeholder="请输入渠道"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="店铺id" prop="channel">
          <el-input
            v-model="queryParams.channel"
            placeholder="请输入店铺id"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="订单Id" prop="orderId">
          <el-input
            v-model="queryParams.orderId"
            placeholder="请输入订单Id"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="计划名称" prop="planName">
          <el-input
            v-model="queryParams.planName"
            placeholder="请输入计划名称"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="观看次数" prop="watchCount">
          <el-input
            v-model="queryParams.watchCount"
            placeholder="请输入观看次数"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="观看成本" prop="watchCost">
          <el-input
            v-model="queryParams.watchCost"
            placeholder="请输入观看成本"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="花费" prop="spent">
          <el-input
            v-model="queryParams.spent"
            placeholder="请输入花费"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="互动量" prop="interactionCount">
          <el-input
            v-model="queryParams.interactionCount"
            placeholder="请输入互动量"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="互动率" prop="interactionRate">
          <el-input
            v-model="queryParams.interactionRate"
            placeholder="请输入互动率"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="平均观看时长" prop="avgWatchDuration">
          <el-input
            v-model="queryParams.avgWatchDuration"
            placeholder="请输入平均观看时长"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="商品点击量" prop="productClickCount">
          <el-input
            v-model="queryParams.productClickCount"
            placeholder="请输入商品点击量"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="商品点击率" prop="productClickRate">
          <el-input
            v-model="queryParams.productClickRate"
            placeholder="请输入商品点击率"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="粉丝关注量" prop="fanFollowers">
          <el-input
            v-model="queryParams.fanFollowers"
            placeholder="请输入粉丝关注量"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="成交订单量" prop="completedOrders">
          <el-input
            v-model="queryParams.completedOrders"
            placeholder="请输入成交订单量"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="成交金额" prop="totalRevenue">
          <el-input
            v-model="queryParams.totalRevenue"
            placeholder="请输入成交金额"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="收藏宝贝量" prop="collectedGoods">
          <el-input
            v-model="queryParams.collectedGoods"
            placeholder="请输入收藏宝贝量"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="商品加购数" prop="addedToCart">
          <el-input
            v-model="queryParams.addedToCart"
            placeholder="请输入商品加购数"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="投资回报率" prop="roi">
          <el-input
            v-model="queryParams.roi"
            placeholder="请输入投资回报率"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="直播点赞量" prop="liveLikes">
          <el-input
            v-model="queryParams.liveLikes"
            placeholder="请输入直播点赞量"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="直播分享量" prop="liveShareNum">
          <el-input
            v-model="queryParams.liveShareNum"
            placeholder="请输入直播分享量"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="直播评论量" prop="liveCommentNum">
          <el-input
            v-model="queryParams.liveCommentNum"
            placeholder="请输入直播评论量"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="预售订单量" prop="presellOrders">
          <el-input
            v-model="queryParams.presellOrders"
            placeholder="请输入预售订单量"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="预售金额" prop="presellAmount">
          <el-input
            v-model="queryParams.presellAmount"
            placeholder="请输入预售金额"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="购物金充值笔数" prop="giftCardRechargeCount">
          <el-input
            v-model="queryParams.giftCardRechargeCount"
            placeholder="请输入购物金充值笔数"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="购物金充值金额" prop="giftCardRechargeAmount">
          <el-input
            v-model="queryParams.giftCardRechargeAmount"
            placeholder="请输入购物金充值金额"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="直接成交笔数" prop="directConversionCount">
          <el-input
            v-model="queryParams.directConversionCount"
            placeholder="请输入直接成交笔数"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="直接成交金额" prop="directRevenue">
          <el-input
            v-model="queryParams.directRevenue"
            placeholder="请输入直接成交金额"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="直接投资回报率" prop="directRoi">
          <el-input
            v-model="queryParams.directRoi"
            placeholder="请输入直接投资回报率"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="月" prop="dataMonth">
          <el-input
            v-model="queryParams.dataMonth"
            placeholder="请输入月"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="周" prop="dataYear">
          <el-input
            v-model="queryParams.dataYear"
            placeholder="请输入周"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="年" prop="dataWeek">
          <el-input
            v-model="queryParams.dataWeek"
            placeholder="请输入年"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
      </div>
      <!-- <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item> -->
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['marketing:BiPromotionContentDwd:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['marketing:BiPromotionContentDwd:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['marketing:BiPromotionContentDwd:remove']"
          >删除</el-button
        >
      </el-col> -->
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['marketing:BiPromotionContentDwd:export']"
          >导出</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button size="mini" plain icon="el-icon-upload" @click="daoru"
          >导入</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="BiPromotionContentDwdList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column
        width="120"
        label="推广内容数据ID"
        align="center"
        prop="id"
      />
      <el-table-column width="120" label="日期" align="center" prop="dataDate">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.dataDate, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column width="120" label="品牌" align="center" prop="brand" />
      <el-table-column width="120" label="渠道" align="center" prop="shopId" />
      <el-table-column
        width="120"
        label="店铺id"
        align="center"
        prop="channel"
      />
      <el-table-column
        width="120"
        label="订单Id"
        align="center"
        prop="orderId"
      />
      <el-table-column
        width="120"
        label="计划名称"
        align="center"
        prop="planName"
      />
      <el-table-column
        width="120"
        label="观看次数"
        align="center"
        prop="watchCount"
      />
      <el-table-column
        width="120"
        label="观看成本"
        align="center"
        prop="watchCost"
      />
      <el-table-column width="120" label="花费" align="center" prop="spent" />
      <el-table-column
        width="120"
        label="互动量"
        align="center"
        prop="interactionCount"
      />
      <el-table-column
        width="120"
        label="互动率"
        align="center"
        prop="interactionRate"
      />
      <el-table-column
        width="120"
        label="平均观看时长"
        align="center"
        prop="avgWatchDuration"
      />
      <el-table-column
        width="120"
        label="商品点击量"
        align="center"
        prop="productClickCount"
      />
      <el-table-column
        width="120"
        label="商品点击率"
        align="center"
        prop="productClickRate"
      />
      <el-table-column
        width="120"
        label="粉丝关注量"
        align="center"
        prop="fanFollowers"
      />
      <el-table-column
        width="120"
        label="成交订单量"
        align="center"
        prop="completedOrders"
      />
      <el-table-column
        width="120"
        label="成交金额"
        align="center"
        prop="totalRevenue"
      />
      <el-table-column
        width="120"
        label="收藏宝贝量"
        align="center"
        prop="collectedGoods"
      />
      <el-table-column
        width="120"
        label="商品加购数"
        align="center"
        prop="addedToCart"
      />
      <el-table-column
        width="120"
        label="投资回报率"
        align="center"
        prop="roi"
      />
      <el-table-column
        width="120"
        label="直播点赞量"
        align="center"
        prop="liveLikes"
      />
      <el-table-column
        width="120"
        label="直播分享量"
        align="center"
        prop="liveShareNum"
      />
      <el-table-column
        width="120"
        label="直播评论量"
        align="center"
        prop="liveCommentNum"
      />
      <el-table-column
        width="120"
        label="预售订单量"
        align="center"
        prop="presellOrders"
      />
      <el-table-column
        width="120"
        label="预售金额"
        align="center"
        prop="presellAmount"
      />
      <el-table-column
        width="120"
        label="购物金充值笔数"
        align="center"
        prop="giftCardRechargeCount"
      />
      <el-table-column
        width="120"
        label="购物金充值金额"
        align="center"
        prop="giftCardRechargeAmount"
      />
      <el-table-column
        width="120"
        label="直接成交笔数"
        align="center"
        prop="directConversionCount"
      />
      <el-table-column
        width="120"
        label="直接成交金额"
        align="center"
        prop="directRevenue"
      />
      <el-table-column
        width="120"
        label="直接投资回报率"
        align="center"
        prop="directRoi"
      />
      <el-table-column width="120" label="月" align="center" prop="dataMonth" />
      <el-table-column width="120" label="周" align="center" prop="dataYear" />
      <el-table-column width="120" label="年" align="center" prop="dataWeek" />
      <el-table-column
        width="120"
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['marketing:BiPromotionContentDwd:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['marketing:BiPromotionContentDwd:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改推广内容数据对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="日期" prop="dataDate">
          <el-date-picker
            clearable
            v-model="form.dataDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="品牌" prop="brand">
          <el-input v-model="form.brand" placeholder="请输入品牌" />
        </el-form-item>
        <el-form-item label="渠道" prop="shopId">
          <el-input v-model="form.shopId" placeholder="请输入渠道" />
        </el-form-item>
        <el-form-item label="店铺id" prop="channel">
          <el-input v-model="form.channel" placeholder="请输入店铺id" />
        </el-form-item>
        <el-form-item label="订单Id" prop="orderId">
          <el-input v-model="form.orderId" placeholder="请输入订单Id" />
        </el-form-item>
        <el-form-item label="计划名称" prop="planName">
          <el-input v-model="form.planName" placeholder="请输入计划名称" />
        </el-form-item>
        <el-form-item label="观看次数" prop="watchCount">
          <el-input v-model="form.watchCount" placeholder="请输入观看次数" />
        </el-form-item>
        <el-form-item label="观看成本" prop="watchCost">
          <el-input v-model="form.watchCost" placeholder="请输入观看成本" />
        </el-form-item>
        <el-form-item label="花费" prop="spent">
          <el-input v-model="form.spent" placeholder="请输入花费" />
        </el-form-item>
        <el-form-item label="互动量" prop="interactionCount">
          <el-input
            v-model="form.interactionCount"
            placeholder="请输入互动量"
          />
        </el-form-item>
        <el-form-item label="互动率" prop="interactionRate">
          <el-input v-model="form.interactionRate" placeholder="请输入互动率" />
        </el-form-item>
        <el-form-item label="平均观看时长" prop="avgWatchDuration">
          <el-input
            v-model="form.avgWatchDuration"
            placeholder="请输入平均观看时长"
          />
        </el-form-item>
        <el-form-item label="商品点击量" prop="productClickCount">
          <el-input
            v-model="form.productClickCount"
            placeholder="请输入商品点击量"
          />
        </el-form-item>
        <el-form-item label="商品点击率" prop="productClickRate">
          <el-input
            v-model="form.productClickRate"
            placeholder="请输入商品点击率"
          />
        </el-form-item>
        <el-form-item label="粉丝关注量" prop="fanFollowers">
          <el-input
            v-model="form.fanFollowers"
            placeholder="请输入粉丝关注量"
          />
        </el-form-item>
        <el-form-item label="成交订单量" prop="completedOrders">
          <el-input
            v-model="form.completedOrders"
            placeholder="请输入成交订单量"
          />
        </el-form-item>
        <el-form-item label="成交金额" prop="totalRevenue">
          <el-input v-model="form.totalRevenue" placeholder="请输入成交金额" />
        </el-form-item>
        <el-form-item label="收藏宝贝量" prop="collectedGoods">
          <el-input
            v-model="form.collectedGoods"
            placeholder="请输入收藏宝贝量"
          />
        </el-form-item>
        <el-form-item label="商品加购数" prop="addedToCart">
          <el-input v-model="form.addedToCart" placeholder="请输入商品加购数" />
        </el-form-item>
        <el-form-item label="投资回报率" prop="roi">
          <el-input v-model="form.roi" placeholder="请输入投资回报率" />
        </el-form-item>
        <el-form-item label="直播点赞量" prop="liveLikes">
          <el-input v-model="form.liveLikes" placeholder="请输入直播点赞量" />
        </el-form-item>
        <el-form-item label="直播分享量" prop="liveShareNum">
          <el-input
            v-model="form.liveShareNum"
            placeholder="请输入直播分享量"
          />
        </el-form-item>
        <el-form-item label="直播评论量" prop="liveCommentNum">
          <el-input
            v-model="form.liveCommentNum"
            placeholder="请输入直播评论量"
          />
        </el-form-item>
        <el-form-item label="预售订单量" prop="presellOrders">
          <el-input
            v-model="form.presellOrders"
            placeholder="请输入预售订单量"
          />
        </el-form-item>
        <el-form-item label="预售金额" prop="presellAmount">
          <el-input v-model="form.presellAmount" placeholder="请输入预售金额" />
        </el-form-item>
        <el-form-item label="购物金充值笔数" prop="giftCardRechargeCount">
          <el-input
            v-model="form.giftCardRechargeCount"
            placeholder="请输入购物金充值笔数"
          />
        </el-form-item>
        <el-form-item label="购物金充值金额" prop="giftCardRechargeAmount">
          <el-input
            v-model="form.giftCardRechargeAmount"
            placeholder="请输入购物金充值金额"
          />
        </el-form-item>
        <el-form-item label="直接成交笔数" prop="directConversionCount">
          <el-input
            v-model="form.directConversionCount"
            placeholder="请输入直接成交笔数"
          />
        </el-form-item>
        <el-form-item label="直接成交金额" prop="directRevenue">
          <el-input
            v-model="form.directRevenue"
            placeholder="请输入直接成交金额"
          />
        </el-form-item>
        <el-form-item label="直接投资回报率" prop="directRoi">
          <el-input
            v-model="form.directRoi"
            placeholder="请输入直接投资回报率"
          />
        </el-form-item>
        <el-form-item label="月" prop="dataMonth">
          <el-input v-model="form.dataMonth" placeholder="请输入月" />
        </el-form-item>
        <el-form-item label="周" prop="dataYear">
          <el-input v-model="form.dataYear" placeholder="请输入周" />
        </el-form-item>
        <el-form-item label="年" prop="dataWeek">
          <el-input v-model="form.dataWeek" placeholder="请输入年" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 添加或修改产品二级信息对话框 :on-change="handleChange"-->
    <el-dialog
      title="导入"
      :visible.sync="dialogVisible"
      width="500px"
      append-to-body
      v-if="dialogVisible"
    >
      <!-- 文件上传-->
      <el-form
        :rules="rules"
        :model="dataForm"
        ref="dataForm"
        label-width="150px"
        @submit.native.prevent
      >
        <el-form-item label="店铺：" prop="name">
          <!-- <el-input
            type="text"
            v-model.trim="dataForm.name"
            clearable
          ></el-input> -->
          <el-cascader
            class="region"
            v-model="dataForm.name"
            placeholder="选择店铺分组"
            clearable
            :options="cascadeList"
            :props="{ checkStrictly: true }"
            style="width: 300px; height: 30px"
          >
          </el-cascader>
        </el-form-item>
        <el-form-item label="文件：" prop="file">
          <el-upload
            class="upload-import"
            ref="uploadImport"
            :http-request="httpRequest"
            action=""
            :on-remove="handleRemove"
            :file-list="fileList"
            :limit="1"
            :on-change="handleChange"
            :auto-upload="false"
            :before-upload="beforeAvatarUpload"
          >
            <!--
            accept="application/zip,.zip" 设置接收的文件类型-->
            <el-button
              v-show="!hasFile"
              slot="trigger"
              size="small"
              type="primary"
              >选取文件</el-button
            >
            <!-- <div slot="tip" class="el-upload__tip">
          只能上传zip文件，且不超过10M
        </div> -->
          </el-upload>
          <!-- 关闭自动上传-->
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitUpload">提交</el-button>
          <!-- <el-button @click="resetForm('ruleForm')">重置</el-button> -->
          <el-button @click="dialogVisible = false">取 消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import {
  listBiPromotionContentDwd,
  getBiPromotionContentDwd,
  delBiPromotionContentDwd,
  addBiPromotionContentDwd,
  updateBiPromotionContentDwd,
} from "@/api/marketing/BiPromotionContentDwd";
import { listAll, importBiKeyword } from "@/api/chart/brandChannelShop";
import timeSearch from "@/views/chart/day/day.vue";
import axios from "axios";
//--------导入token
import { getToken } from "@/utils/auth";
export default {
  name: "BiPromotionContentDwd",
  data() {
    return {
      cascadeList: [],
      dataForm: {
        name: ["VFU", "天猫", "vfu运动旗舰店"],
        file: null,
      },
      rules: {
        name: [
          { required: true, message: "请输入名称", trigger: "blur" },
          { max: 50, message: "最长可输入50个字符", trigger: "blur" },
          // { validator: isvalidatName, trigger: "blur" },
        ],
        file: [{ required: true, message: "请选择上传文件", trigger: "blur" }],
      },
      hasFile: false,
      fileList: [],
      dialogVisible: false,
      pjtUrl: process.env.VUE_APP_BASE_API,
      dayActive: 2,
      timeArr: [
        { value: "2", label: "昨天" },
        { value: "7", label: "最近7天" },
        { value: "30", label: "最近30天" },
        { value: "365", label: "最近一年" },
        { value: "1", label: "日" },
      ],
      timeGap: { startTime: "", endTime: "" },
      isOpen: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 推广内容数据表格数据
      BiPromotionContentDwdList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        dataDate: null,
        brand: null,
        shopId: null,
        channel: null,
        orderId: null,
        planName: null,
        watchCount: null,
        watchCost: null,
        spent: null,
        interactionCount: null,
        interactionRate: null,
        avgWatchDuration: null,
        productClickCount: null,
        productClickRate: null,
        fanFollowers: null,
        completedOrders: null,
        totalRevenue: null,
        collectedGoods: null,
        addedToCart: null,
        roi: null,
        liveLikes: null,
        liveShareNum: null,
        liveCommentNum: null,
        presellOrders: null,
        presellAmount: null,
        giftCardRechargeCount: null,
        giftCardRechargeAmount: null,
        directConversionCount: null,
        directRevenue: null,
        directRoi: null,
        dataMonth: null,
        dataYear: null,
        dataWeek: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
    };
  },
  created() {
    this.getList();
    this.getdataSourceList();
  },
  methods: {
    //图片上传前的相关判断
    beforeAvatarUpload(file) {
      // const isJPG = file.type == 'image/jpeg' || file.type == 'image/png';
      const isLt2M = file.size / 1024 / 1024 < 100;
      // if (!isJPG) {
      //     this.$message.error('上传头像图片只能是 JPG/PNG 格式!');
      // }
      if (!isLt2M) {
        this.$message.error("上传导入文件大小不能超过 100MB!");
      }

      return isLt2M;
    },
    handleRemove(file, fileList) {
      if (!fileList.length) {
        this.hasFile = false;
      }
      this.dataForm.file = null;
    },
    handleChange(file, fileList) {
      if (fileList.length >= 2) {
        return;
      }
      if (fileList.length === 1) {
        this.hasFile = true;
      }
      this.dataForm.file = file;
    },
    //确定按钮
    //调用组件upload的submit方法，从而触发httpRequest方法，实现手动上传
    submitUpload() {
      this.$refs["dataForm"].validate((valid) => {
        if (valid) {
          this.$refs.uploadImport.submit();
        }
      });
    },
    httpRequest(param) {
      if (this.dataForm.name.length < 3) {
        this.$modal.msgWarning("请选择到店铺");
        return;
      }
      let fd = new FormData();
      fd.append("file", param.file); // 传文件
      fd.append("salesGrade", this.dataForm.name);
      //dataPar.file.raw
      console.log(JSON.stringify(fd));
      this.openLoading();
      axios
        .post(
          process.env.VUE_APP_BASE_API +
            "/marketing/BiPromotionContentDwd/importData",
          fd,
          {
            headers: {
              header: { responseType: "blob" },

              Authorization: "Bearer " + getToken(),
              "Content-Type": "multipart/form-data",
            }, //定义内容格式,很重要
            // timeout: 20000,
          }
        )
        .then((response) => {
          console.log(response);
          this.dialogVisible = false;

          this.$modal.closeLoading();
          // this.$modal.msgSuccess("导入成功");
          this.hasFile = false;
          if (response.data.code == 200) {
            this.$modal.msgSuccess("导入成功");
            this.getList();
          } else {
            this.$modal.msgError("导入失败");
          }
        });
    },
    //部门文件导入修改打开
    daoru() {
      this.dialogVisible = true;
    },
    // 打开加载层
    openLoading() {
      this.$modal.loading("正在导入，请稍候！");
    },
    /** 查询品牌渠道店铺关系列表 */
    getdataSourceList() {
      listAll().then((response) => {
        let result = this.transformData(response);
        this.cascadeList = result;
      });
    },
    //店铺渠道品牌转换

    transformData(data) {
      let result = [];

      data.forEach((item) => {
        let brand = item.brand;
        let channel = item.channel;
        let shopName = item.shopName;

        // 如果brand在结果数组中不存在，则创建一个新的数组
        let brandIndex = result.findIndex(
          (brandObj) => brandObj.label === brand
        );
        if (brandIndex === -1) {
          result.push({
            label: brand,
            value: brand,
            children: [],
          });
          brandIndex = result.length - 1;
        }

        // 如果channel在当前brand的children数组中不存在，则创建一个新的数组
        let channelIndex = result[brandIndex].children.findIndex(
          (channelObj) => channelObj.label === channel
        );
        if (channelIndex === -1) {
          result[brandIndex].children.push({
            label: channel,
            value: channel,
            children: [],
          });
          channelIndex = result[brandIndex].children.length - 1;
        }

        // 如果shopName在当前channel的children数组中不存在，则创建一个新的数组
        let shopIndex = result[brandIndex].children[
          channelIndex
        ].children.findIndex((shopObj) => shopObj.label === shopName);
        if (shopIndex === -1) {
          result[brandIndex].children[channelIndex].children.push({
            label: shopName,
            value: shopName,
            // children: []
          });
        }
      });

      return result;
    },
    handleRefreshCache() {
      this.$modal.msgWarning("数据正在同步，请稍候");
      const obj = {
        startDate: this.timeGap.startTime,
        endDate: this.timeGap.endTime,
      };
      insertBatchFirstData(obj).then(() => {
        this.$modal.msgSuccess("同步数据成功");
        this.getList();
        // this.$store.dispatch('dict/cleanDict');
      });
    },
    handleLable() {
      this.$modal.msgWarning("数据正在同步，请稍候");
      const obj = {
        startDate: this.timeGap.startTime,
        endDate: this.timeGap.endTime,
      };
      updateKeywordLabel(obj).then(() => {
        this.$modal.msgSuccess("同步数据成功");
        this.getList();
        // this.$store.dispatch('dict/cleanDict');
      });
    },
    //时间控件
    changDay(val) {
      this.dayActive = val;
      this.timeGap.startTime = val[0];
      this.timeGap.endTime = val[1];
    },
    getDateArr(value) {
      this.timeGap.startTime = value[0];
      this.timeGap.endTime = value[1];
      console.log(JSON.stringify(this.timeGap));
      // this.queryParams.payDayStart = this.timeGap.startTime;
      // this.queryParams.payDayEnd = this.timeGap.endTime;

      // this.getList();

      this.dayActive = 1;
    },
    //搜索栏展示与收起
    shouqi() {
      // console.log(1);
      this.isOpen = !this.isOpen;
    },
    /** 查询推广内容数据列表 */
    getList() {
      this.loading = true;
      listBiPromotionContentDwd(this.queryParams).then((response) => {
        this.BiPromotionContentDwdList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        dataDate: null,
        brand: null,
        shopId: null,
        channel: null,
        orderId: null,
        planName: null,
        watchCount: null,
        watchCost: null,
        spent: null,
        interactionCount: null,
        interactionRate: null,
        avgWatchDuration: null,
        productClickCount: null,
        productClickRate: null,
        fanFollowers: null,
        completedOrders: null,
        totalRevenue: null,
        collectedGoods: null,
        addedToCart: null,
        roi: null,
        liveLikes: null,
        liveShareNum: null,
        liveCommentNum: null,
        presellOrders: null,
        presellAmount: null,
        giftCardRechargeCount: null,
        giftCardRechargeAmount: null,
        directConversionCount: null,
        directRevenue: null,
        directRoi: null,
        dataMonth: null,
        dataYear: null,
        dataWeek: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加推广内容数据";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getBiPromotionContentDwd(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改推广内容数据";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateBiPromotionContentDwd(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addBiPromotionContentDwd(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除推广内容数据编号为"' + ids + '"的数据项？')
        .then(function () {
          return delBiPromotionContentDwd(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "marketing/BiPromotionContentDwd/export",
        {
          ...this.queryParams,
        },
        `BiPromotionContentDwd_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
